{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "8113820b",
   "metadata": {},
   "source": [
    "# 如何使用表格的内容\n",
    "## 我们今天继续玩表格\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "a399f5d4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "让我们看看sh.603799华友钴业的日K线\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-07-01</th>\n",
       "      <td>95.51</td>\n",
       "      <td>98.98</td>\n",
       "      <td>94.30</td>\n",
       "      <td>97.08</td>\n",
       "      <td>18269788</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-04</th>\n",
       "      <td>95.90</td>\n",
       "      <td>99.10</td>\n",
       "      <td>94.40</td>\n",
       "      <td>96.65</td>\n",
       "      <td>23120958</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-05</th>\n",
       "      <td>99.72</td>\n",
       "      <td>102.38</td>\n",
       "      <td>97.23</td>\n",
       "      <td>99.79</td>\n",
       "      <td>31773677</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-06</th>\n",
       "      <td>97.60</td>\n",
       "      <td>98.80</td>\n",
       "      <td>91.81</td>\n",
       "      <td>93.34</td>\n",
       "      <td>46549649</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-07</th>\n",
       "      <td>92.02</td>\n",
       "      <td>93.71</td>\n",
       "      <td>88.80</td>\n",
       "      <td>93.12</td>\n",
       "      <td>44028123</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-08</th>\n",
       "      <td>93.18</td>\n",
       "      <td>94.88</td>\n",
       "      <td>91.00</td>\n",
       "      <td>91.18</td>\n",
       "      <td>25046048</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             open    high    low  close    volume\n",
       "date                                             \n",
       "2022-07-01  95.51   98.98  94.30  97.08  18269788\n",
       "2022-07-04  95.90   99.10  94.40  96.65  23120958\n",
       "2022-07-05  99.72  102.38  97.23  99.79  31773677\n",
       "2022-07-06  97.60   98.80  91.81  93.34  46549649\n",
       "2022-07-07  92.02   93.71  88.80  93.12  44028123\n",
       "2022-07-08  93.18   94.88  91.00  91.18  25046048"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from localdata import anyone, daily\n",
    "data, code, name = anyone(klen = 6)\n",
    "\n",
    "print('让我们看看' + code + name + '的日K线')\n",
    "data"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7ab8f695",
   "metadata": {},
   "source": [
    "### 使用表格里的内容\n",
    "#### 按列使用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "58791cd1",
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "date\n",
       "2022-07-01    4.99\n",
       "2022-07-04    4.91\n",
       "2022-07-05    5.00\n",
       "2022-07-06    4.93\n",
       "2022-07-07    4.87\n",
       "2022-07-08    4.86\n",
       "Name: open, dtype: float64"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data['open']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "224e0e41",
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "date\n",
       "2022-07-01    4.99\n",
       "2022-07-04    4.91\n",
       "2022-07-05    5.00\n",
       "2022-07-06    4.93\n",
       "2022-07-07    4.87\n",
       "2022-07-08    4.86\n",
       "Name: open, dtype: float64"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.open"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "00f7aac2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "date\n",
       "2022-07-01    4990.0\n",
       "2022-07-04    4910.0\n",
       "2022-07-05    5000.0\n",
       "2022-07-06    4930.0\n",
       "2022-07-07    4870.0\n",
       "2022-07-08    4860.0\n",
       "Name: open, dtype: float64"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.open * 1000"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "b3d4cff4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-07-01</th>\n",
       "      <td>4.99</td>\n",
       "      <td>5.05</td>\n",
       "      <td>4.93</td>\n",
       "      <td>4.95</td>\n",
       "      <td>34828502</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-04</th>\n",
       "      <td>4.91</td>\n",
       "      <td>5.05</td>\n",
       "      <td>4.82</td>\n",
       "      <td>5.02</td>\n",
       "      <td>47261339</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-05</th>\n",
       "      <td>5.00</td>\n",
       "      <td>5.03</td>\n",
       "      <td>4.91</td>\n",
       "      <td>4.96</td>\n",
       "      <td>32331915</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-06</th>\n",
       "      <td>4.93</td>\n",
       "      <td>4.94</td>\n",
       "      <td>4.85</td>\n",
       "      <td>4.86</td>\n",
       "      <td>26884071</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-07</th>\n",
       "      <td>4.87</td>\n",
       "      <td>4.89</td>\n",
       "      <td>4.84</td>\n",
       "      <td>4.86</td>\n",
       "      <td>22427601</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-08</th>\n",
       "      <td>4.86</td>\n",
       "      <td>4.93</td>\n",
       "      <td>4.86</td>\n",
       "      <td>4.89</td>\n",
       "      <td>24603067</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            open  high   low  close    volume\n",
       "date                                         \n",
       "2022-07-01  4.99  5.05  4.93   4.95  34828502\n",
       "2022-07-04  4.91  5.05  4.82   5.02  47261339\n",
       "2022-07-05  5.00  5.03  4.91   4.96  32331915\n",
       "2022-07-06  4.93  4.94  4.85   4.86  26884071\n",
       "2022-07-07  4.87  4.89  4.84   4.86  22427601\n",
       "2022-07-08  4.86  4.93  4.86   4.89  24603067"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "5d54be8f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "date\n",
       "2022-07-01   -0.04\n",
       "2022-07-04    0.11\n",
       "2022-07-05   -0.04\n",
       "2022-07-06   -0.07\n",
       "2022-07-07   -0.01\n",
       "2022-07-08    0.03\n",
       "dtype: float64"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.close - data.open "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "fe698177",
   "metadata": {},
   "outputs": [],
   "source": [
    "inc_per = (data.close - data.open) / data.open"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "d19e2ff4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "date\n",
       "2022-07-01   -0.008016\n",
       "2022-07-04    0.022403\n",
       "2022-07-05   -0.008000\n",
       "2022-07-06   -0.014199\n",
       "2022-07-07   -0.002053\n",
       "2022-07-08    0.006173\n",
       "dtype: float64"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inc_per"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "23f94bdb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-07-01</th>\n",
       "      <td>4.99</td>\n",
       "      <td>5.05</td>\n",
       "      <td>4.93</td>\n",
       "      <td>4.95</td>\n",
       "      <td>34828502</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-04</th>\n",
       "      <td>4.91</td>\n",
       "      <td>5.05</td>\n",
       "      <td>4.82</td>\n",
       "      <td>5.02</td>\n",
       "      <td>47261339</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-05</th>\n",
       "      <td>5.00</td>\n",
       "      <td>5.03</td>\n",
       "      <td>4.91</td>\n",
       "      <td>4.96</td>\n",
       "      <td>32331915</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-06</th>\n",
       "      <td>4.93</td>\n",
       "      <td>4.94</td>\n",
       "      <td>4.85</td>\n",
       "      <td>4.86</td>\n",
       "      <td>26884071</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-07</th>\n",
       "      <td>4.87</td>\n",
       "      <td>4.89</td>\n",
       "      <td>4.84</td>\n",
       "      <td>4.86</td>\n",
       "      <td>22427601</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-08</th>\n",
       "      <td>4.86</td>\n",
       "      <td>4.93</td>\n",
       "      <td>4.86</td>\n",
       "      <td>4.89</td>\n",
       "      <td>24603067</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            open  high   low  close    volume\n",
       "date                                         \n",
       "2022-07-01  4.99  5.05  4.93   4.95  34828502\n",
       "2022-07-04  4.91  5.05  4.82   5.02  47261339\n",
       "2022-07-05  5.00  5.03  4.91   4.96  32331915\n",
       "2022-07-06  4.93  4.94  4.85   4.86  26884071\n",
       "2022-07-07  4.87  4.89  4.84   4.86  22427601\n",
       "2022-07-08  4.86  4.93  4.86   4.89  24603067"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "596d0383",
   "metadata": {},
   "source": [
    "- 把计算结果放入表格"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "d2ace7e3",
   "metadata": {},
   "outputs": [],
   "source": [
    "data['increase'] = data.close - data.open"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "5f3fe156",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "      <th>increase</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-07-01</th>\n",
       "      <td>4.99</td>\n",
       "      <td>5.05</td>\n",
       "      <td>4.93</td>\n",
       "      <td>4.95</td>\n",
       "      <td>34828502</td>\n",
       "      <td>-0.04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-04</th>\n",
       "      <td>4.91</td>\n",
       "      <td>5.05</td>\n",
       "      <td>4.82</td>\n",
       "      <td>5.02</td>\n",
       "      <td>47261339</td>\n",
       "      <td>0.11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-05</th>\n",
       "      <td>5.00</td>\n",
       "      <td>5.03</td>\n",
       "      <td>4.91</td>\n",
       "      <td>4.96</td>\n",
       "      <td>32331915</td>\n",
       "      <td>-0.04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-06</th>\n",
       "      <td>4.93</td>\n",
       "      <td>4.94</td>\n",
       "      <td>4.85</td>\n",
       "      <td>4.86</td>\n",
       "      <td>26884071</td>\n",
       "      <td>-0.07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-07</th>\n",
       "      <td>4.87</td>\n",
       "      <td>4.89</td>\n",
       "      <td>4.84</td>\n",
       "      <td>4.86</td>\n",
       "      <td>22427601</td>\n",
       "      <td>-0.01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-08</th>\n",
       "      <td>4.86</td>\n",
       "      <td>4.93</td>\n",
       "      <td>4.86</td>\n",
       "      <td>4.89</td>\n",
       "      <td>24603067</td>\n",
       "      <td>0.03</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            open  high   low  close    volume  increase\n",
       "date                                                   \n",
       "2022-07-01  4.99  5.05  4.93   4.95  34828502     -0.04\n",
       "2022-07-04  4.91  5.05  4.82   5.02  47261339      0.11\n",
       "2022-07-05  5.00  5.03  4.91   4.96  32331915     -0.04\n",
       "2022-07-06  4.93  4.94  4.85   4.86  26884071     -0.07\n",
       "2022-07-07  4.87  4.89  4.84   4.86  22427601     -0.01\n",
       "2022-07-08  4.86  4.93  4.86   4.89  24603067      0.03"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "09dd1eef",
   "metadata": {},
   "outputs": [],
   "source": [
    "data['increase_percent'] = (data.close - data.open) / data.open"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "3e5f2a80",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "      <th>increase</th>\n",
       "      <th>increase_percent</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-07-01</th>\n",
       "      <td>4.99</td>\n",
       "      <td>5.05</td>\n",
       "      <td>4.93</td>\n",
       "      <td>4.95</td>\n",
       "      <td>34828502</td>\n",
       "      <td>-0.04</td>\n",
       "      <td>-0.008016</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-04</th>\n",
       "      <td>4.91</td>\n",
       "      <td>5.05</td>\n",
       "      <td>4.82</td>\n",
       "      <td>5.02</td>\n",
       "      <td>47261339</td>\n",
       "      <td>0.11</td>\n",
       "      <td>0.022403</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-05</th>\n",
       "      <td>5.00</td>\n",
       "      <td>5.03</td>\n",
       "      <td>4.91</td>\n",
       "      <td>4.96</td>\n",
       "      <td>32331915</td>\n",
       "      <td>-0.04</td>\n",
       "      <td>-0.008000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-06</th>\n",
       "      <td>4.93</td>\n",
       "      <td>4.94</td>\n",
       "      <td>4.85</td>\n",
       "      <td>4.86</td>\n",
       "      <td>26884071</td>\n",
       "      <td>-0.07</td>\n",
       "      <td>-0.014199</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-07</th>\n",
       "      <td>4.87</td>\n",
       "      <td>4.89</td>\n",
       "      <td>4.84</td>\n",
       "      <td>4.86</td>\n",
       "      <td>22427601</td>\n",
       "      <td>-0.01</td>\n",
       "      <td>-0.002053</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-08</th>\n",
       "      <td>4.86</td>\n",
       "      <td>4.93</td>\n",
       "      <td>4.86</td>\n",
       "      <td>4.89</td>\n",
       "      <td>24603067</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.006173</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            open  high   low  close    volume  increase  increase_percent\n",
       "date                                                                     \n",
       "2022-07-01  4.99  5.05  4.93   4.95  34828502     -0.04         -0.008016\n",
       "2022-07-04  4.91  5.05  4.82   5.02  47261339      0.11          0.022403\n",
       "2022-07-05  5.00  5.03  4.91   4.96  32331915     -0.04         -0.008000\n",
       "2022-07-06  4.93  4.94  4.85   4.86  26884071     -0.07         -0.014199\n",
       "2022-07-07  4.87  4.89  4.84   4.86  22427601     -0.01         -0.002053\n",
       "2022-07-08  4.86  4.93  4.86   4.89  24603067      0.03          0.006173"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "d01aec41",
   "metadata": {},
   "outputs": [],
   "source": [
    "data_new = data.drop(['increase_percent', 'increase'], axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "9bb0c78a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-07-01</th>\n",
       "      <td>4.99</td>\n",
       "      <td>5.05</td>\n",
       "      <td>4.93</td>\n",
       "      <td>4.95</td>\n",
       "      <td>34828502</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-04</th>\n",
       "      <td>4.91</td>\n",
       "      <td>5.05</td>\n",
       "      <td>4.82</td>\n",
       "      <td>5.02</td>\n",
       "      <td>47261339</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-05</th>\n",
       "      <td>5.00</td>\n",
       "      <td>5.03</td>\n",
       "      <td>4.91</td>\n",
       "      <td>4.96</td>\n",
       "      <td>32331915</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-06</th>\n",
       "      <td>4.93</td>\n",
       "      <td>4.94</td>\n",
       "      <td>4.85</td>\n",
       "      <td>4.86</td>\n",
       "      <td>26884071</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-07</th>\n",
       "      <td>4.87</td>\n",
       "      <td>4.89</td>\n",
       "      <td>4.84</td>\n",
       "      <td>4.86</td>\n",
       "      <td>22427601</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-08</th>\n",
       "      <td>4.86</td>\n",
       "      <td>4.93</td>\n",
       "      <td>4.86</td>\n",
       "      <td>4.89</td>\n",
       "      <td>24603067</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            open  high   low  close    volume\n",
       "date                                         \n",
       "2022-07-01  4.99  5.05  4.93   4.95  34828502\n",
       "2022-07-04  4.91  5.05  4.82   5.02  47261339\n",
       "2022-07-05  5.00  5.03  4.91   4.96  32331915\n",
       "2022-07-06  4.93  4.94  4.85   4.86  26884071\n",
       "2022-07-07  4.87  4.89  4.84   4.86  22427601\n",
       "2022-07-08  4.86  4.93  4.86   4.89  24603067"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_new"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "afce14fc",
   "metadata": {},
   "source": [
    "三种让data恢复成五个列的方法\n",
    "1、重新执行anyone，获取新的数据\n",
    "2、data = data.drop(...)\n",
    "3、data.drop(..., inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "id": "6c7a9c48",
   "metadata": {},
   "outputs": [],
   "source": [
    "data['increase'] = data.close - data.open\n",
    "data['increase_percent'] = (data.close - data.open) / data.open"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "id": "9a01330b",
   "metadata": {},
   "outputs": [],
   "source": [
    "data_new = data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "id": "d162c2c9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "      <th>increase</th>\n",
       "      <th>increase_percent</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-07-01</th>\n",
       "      <td>95.51</td>\n",
       "      <td>98.98</td>\n",
       "      <td>94.30</td>\n",
       "      <td>97.08</td>\n",
       "      <td>18269788</td>\n",
       "      <td>1.57</td>\n",
       "      <td>0.016438</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-04</th>\n",
       "      <td>95.90</td>\n",
       "      <td>99.10</td>\n",
       "      <td>94.40</td>\n",
       "      <td>96.65</td>\n",
       "      <td>23120958</td>\n",
       "      <td>0.75</td>\n",
       "      <td>0.007821</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-05</th>\n",
       "      <td>99.72</td>\n",
       "      <td>102.38</td>\n",
       "      <td>97.23</td>\n",
       "      <td>99.79</td>\n",
       "      <td>31773677</td>\n",
       "      <td>0.07</td>\n",
       "      <td>0.000702</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-06</th>\n",
       "      <td>97.60</td>\n",
       "      <td>98.80</td>\n",
       "      <td>91.81</td>\n",
       "      <td>93.34</td>\n",
       "      <td>46549649</td>\n",
       "      <td>-4.26</td>\n",
       "      <td>-0.043648</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-07</th>\n",
       "      <td>92.02</td>\n",
       "      <td>93.71</td>\n",
       "      <td>88.80</td>\n",
       "      <td>93.12</td>\n",
       "      <td>44028123</td>\n",
       "      <td>1.10</td>\n",
       "      <td>0.011954</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-08</th>\n",
       "      <td>93.18</td>\n",
       "      <td>94.88</td>\n",
       "      <td>91.00</td>\n",
       "      <td>91.18</td>\n",
       "      <td>25046048</td>\n",
       "      <td>-2.00</td>\n",
       "      <td>-0.021464</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             open    high    low  close    volume  increase  increase_percent\n",
       "date                                                                         \n",
       "2022-07-01  95.51   98.98  94.30  97.08  18269788      1.57          0.016438\n",
       "2022-07-04  95.90   99.10  94.40  96.65  23120958      0.75          0.007821\n",
       "2022-07-05  99.72  102.38  97.23  99.79  31773677      0.07          0.000702\n",
       "2022-07-06  97.60   98.80  91.81  93.34  46549649     -4.26         -0.043648\n",
       "2022-07-07  92.02   93.71  88.80  93.12  44028123      1.10          0.011954\n",
       "2022-07-08  93.18   94.88  91.00  91.18  25046048     -2.00         -0.021464"
      ]
     },
     "execution_count": 103,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_new"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "id": "c1b3835d",
   "metadata": {},
   "outputs": [],
   "source": [
    "data2 = data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "id": "5d0d31a5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "      <th>increase</th>\n",
       "      <th>increase_percent</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-07-01</th>\n",
       "      <td>95.51</td>\n",
       "      <td>98.98</td>\n",
       "      <td>94.30</td>\n",
       "      <td>97.08</td>\n",
       "      <td>18269788</td>\n",
       "      <td>1.57</td>\n",
       "      <td>0.016438</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-04</th>\n",
       "      <td>95.90</td>\n",
       "      <td>99.10</td>\n",
       "      <td>94.40</td>\n",
       "      <td>96.65</td>\n",
       "      <td>23120958</td>\n",
       "      <td>0.75</td>\n",
       "      <td>0.007821</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-05</th>\n",
       "      <td>99.72</td>\n",
       "      <td>102.38</td>\n",
       "      <td>97.23</td>\n",
       "      <td>99.79</td>\n",
       "      <td>31773677</td>\n",
       "      <td>0.07</td>\n",
       "      <td>0.000702</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-06</th>\n",
       "      <td>97.60</td>\n",
       "      <td>98.80</td>\n",
       "      <td>91.81</td>\n",
       "      <td>93.34</td>\n",
       "      <td>46549649</td>\n",
       "      <td>-4.26</td>\n",
       "      <td>-0.043648</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-07</th>\n",
       "      <td>92.02</td>\n",
       "      <td>93.71</td>\n",
       "      <td>88.80</td>\n",
       "      <td>93.12</td>\n",
       "      <td>44028123</td>\n",
       "      <td>1.10</td>\n",
       "      <td>0.011954</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-08</th>\n",
       "      <td>93.18</td>\n",
       "      <td>94.88</td>\n",
       "      <td>91.00</td>\n",
       "      <td>91.18</td>\n",
       "      <td>25046048</td>\n",
       "      <td>-2.00</td>\n",
       "      <td>-0.021464</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             open    high    low  close    volume  increase  increase_percent\n",
       "date                                                                         \n",
       "2022-07-01  95.51   98.98  94.30  97.08  18269788      1.57          0.016438\n",
       "2022-07-04  95.90   99.10  94.40  96.65  23120958      0.75          0.007821\n",
       "2022-07-05  99.72  102.38  97.23  99.79  31773677      0.07          0.000702\n",
       "2022-07-06  97.60   98.80  91.81  93.34  46549649     -4.26         -0.043648\n",
       "2022-07-07  92.02   93.71  88.80  93.12  44028123      1.10          0.011954\n",
       "2022-07-08  93.18   94.88  91.00  91.18  25046048     -2.00         -0.021464"
      ]
     },
     "execution_count": 102,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "id": "ab25a8a1",
   "metadata": {},
   "outputs": [],
   "source": [
    "data3, code, name = anyone()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "id": "3d0a6003",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-06-27</th>\n",
       "      <td>47.20</td>\n",
       "      <td>48.05</td>\n",
       "      <td>43.88</td>\n",
       "      <td>44.09</td>\n",
       "      <td>11579012</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-06-28</th>\n",
       "      <td>43.57</td>\n",
       "      <td>44.00</td>\n",
       "      <td>42.88</td>\n",
       "      <td>43.44</td>\n",
       "      <td>8229144</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-06-29</th>\n",
       "      <td>43.13</td>\n",
       "      <td>44.47</td>\n",
       "      <td>42.90</td>\n",
       "      <td>43.58</td>\n",
       "      <td>8654650</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-06-30</th>\n",
       "      <td>43.61</td>\n",
       "      <td>45.68</td>\n",
       "      <td>43.61</td>\n",
       "      <td>45.00</td>\n",
       "      <td>8006156</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-01</th>\n",
       "      <td>45.02</td>\n",
       "      <td>46.23</td>\n",
       "      <td>43.95</td>\n",
       "      <td>45.36</td>\n",
       "      <td>6578720</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-04</th>\n",
       "      <td>45.48</td>\n",
       "      <td>49.00</td>\n",
       "      <td>45.31</td>\n",
       "      <td>48.59</td>\n",
       "      <td>14099456</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-05</th>\n",
       "      <td>48.65</td>\n",
       "      <td>49.00</td>\n",
       "      <td>45.09</td>\n",
       "      <td>45.86</td>\n",
       "      <td>14931320</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-06</th>\n",
       "      <td>45.77</td>\n",
       "      <td>45.82</td>\n",
       "      <td>42.00</td>\n",
       "      <td>42.87</td>\n",
       "      <td>21326163</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-07</th>\n",
       "      <td>42.87</td>\n",
       "      <td>44.44</td>\n",
       "      <td>42.01</td>\n",
       "      <td>43.74</td>\n",
       "      <td>12020260</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-08</th>\n",
       "      <td>43.53</td>\n",
       "      <td>44.16</td>\n",
       "      <td>42.70</td>\n",
       "      <td>43.25</td>\n",
       "      <td>7139823</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             open   high    low  close    volume\n",
       "date                                            \n",
       "2022-06-27  47.20  48.05  43.88  44.09  11579012\n",
       "2022-06-28  43.57  44.00  42.88  43.44   8229144\n",
       "2022-06-29  43.13  44.47  42.90  43.58   8654650\n",
       "2022-06-30  43.61  45.68  43.61  45.00   8006156\n",
       "2022-07-01  45.02  46.23  43.95  45.36   6578720\n",
       "2022-07-04  45.48  49.00  45.31  48.59  14099456\n",
       "2022-07-05  48.65  49.00  45.09  45.86  14931320\n",
       "2022-07-06  45.77  45.82  42.00  42.87  21326163\n",
       "2022-07-07  42.87  44.44  42.01  43.74  12020260\n",
       "2022-07-08  43.53  44.16  42.70  43.25   7139823"
      ]
     },
     "execution_count": 105,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "id": "864f17fd",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = data3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "id": "1985f5fb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-06-27</th>\n",
       "      <td>47.20</td>\n",
       "      <td>48.05</td>\n",
       "      <td>43.88</td>\n",
       "      <td>44.09</td>\n",
       "      <td>11579012</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-06-28</th>\n",
       "      <td>43.57</td>\n",
       "      <td>44.00</td>\n",
       "      <td>42.88</td>\n",
       "      <td>43.44</td>\n",
       "      <td>8229144</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-06-29</th>\n",
       "      <td>43.13</td>\n",
       "      <td>44.47</td>\n",
       "      <td>42.90</td>\n",
       "      <td>43.58</td>\n",
       "      <td>8654650</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-06-30</th>\n",
       "      <td>43.61</td>\n",
       "      <td>45.68</td>\n",
       "      <td>43.61</td>\n",
       "      <td>45.00</td>\n",
       "      <td>8006156</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-01</th>\n",
       "      <td>45.02</td>\n",
       "      <td>46.23</td>\n",
       "      <td>43.95</td>\n",
       "      <td>45.36</td>\n",
       "      <td>6578720</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-04</th>\n",
       "      <td>45.48</td>\n",
       "      <td>49.00</td>\n",
       "      <td>45.31</td>\n",
       "      <td>48.59</td>\n",
       "      <td>14099456</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-05</th>\n",
       "      <td>48.65</td>\n",
       "      <td>49.00</td>\n",
       "      <td>45.09</td>\n",
       "      <td>45.86</td>\n",
       "      <td>14931320</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-06</th>\n",
       "      <td>45.77</td>\n",
       "      <td>45.82</td>\n",
       "      <td>42.00</td>\n",
       "      <td>42.87</td>\n",
       "      <td>21326163</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-07</th>\n",
       "      <td>42.87</td>\n",
       "      <td>44.44</td>\n",
       "      <td>42.01</td>\n",
       "      <td>43.74</td>\n",
       "      <td>12020260</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-08</th>\n",
       "      <td>43.53</td>\n",
       "      <td>44.16</td>\n",
       "      <td>42.70</td>\n",
       "      <td>43.25</td>\n",
       "      <td>7139823</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             open   high    low  close    volume\n",
       "date                                            \n",
       "2022-06-27  47.20  48.05  43.88  44.09  11579012\n",
       "2022-06-28  43.57  44.00  42.88  43.44   8229144\n",
       "2022-06-29  43.13  44.47  42.90  43.58   8654650\n",
       "2022-06-30  43.61  45.68  43.61  45.00   8006156\n",
       "2022-07-01  45.02  46.23  43.95  45.36   6578720\n",
       "2022-07-04  45.48  49.00  45.31  48.59  14099456\n",
       "2022-07-05  48.65  49.00  45.09  45.86  14931320\n",
       "2022-07-06  45.77  45.82  42.00  42.87  21326163\n",
       "2022-07-07  42.87  44.44  42.01  43.74  12020260\n",
       "2022-07-08  43.53  44.16  42.70  43.25   7139823"
      ]
     },
     "execution_count": 107,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "id": "ded58e27",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = data.drop(['increase_percent', 'increase'], axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "id": "140c99e7",
   "metadata": {},
   "outputs": [],
   "source": [
    "data.drop(['increase_percent', 'increase'], axis=1, inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "id": "598a3ed0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 101,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3bf0e276",
   "metadata": {},
   "source": [
    "- 按行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "id": "85c8e841",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(datetime.datetime(2022, 7, 5, 0, 0), datetime.datetime(2022, 7, 4, 0, 0))"
      ]
     },
     "execution_count": 115,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import datetime as dt\n",
    "oneDay = dt.datetime(2022, 7, 5)\n",
    "otherDay = dt.datetime(2022, 7, 4)\n",
    "oneDay, otherDay"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "id": "d28b50a1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-06-27</th>\n",
       "      <td>47.20</td>\n",
       "      <td>48.05</td>\n",
       "      <td>43.88</td>\n",
       "      <td>44.09</td>\n",
       "      <td>11579012</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-06-28</th>\n",
       "      <td>43.57</td>\n",
       "      <td>44.00</td>\n",
       "      <td>42.88</td>\n",
       "      <td>43.44</td>\n",
       "      <td>8229144</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-06-29</th>\n",
       "      <td>43.13</td>\n",
       "      <td>44.47</td>\n",
       "      <td>42.90</td>\n",
       "      <td>43.58</td>\n",
       "      <td>8654650</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-06-30</th>\n",
       "      <td>43.61</td>\n",
       "      <td>45.68</td>\n",
       "      <td>43.61</td>\n",
       "      <td>45.00</td>\n",
       "      <td>8006156</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-01</th>\n",
       "      <td>45.02</td>\n",
       "      <td>46.23</td>\n",
       "      <td>43.95</td>\n",
       "      <td>45.36</td>\n",
       "      <td>6578720</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-04</th>\n",
       "      <td>45.48</td>\n",
       "      <td>49.00</td>\n",
       "      <td>45.31</td>\n",
       "      <td>48.59</td>\n",
       "      <td>14099456</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-05</th>\n",
       "      <td>48.65</td>\n",
       "      <td>49.00</td>\n",
       "      <td>45.09</td>\n",
       "      <td>45.86</td>\n",
       "      <td>14931320</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-06</th>\n",
       "      <td>45.77</td>\n",
       "      <td>45.82</td>\n",
       "      <td>42.00</td>\n",
       "      <td>42.87</td>\n",
       "      <td>21326163</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-07</th>\n",
       "      <td>42.87</td>\n",
       "      <td>44.44</td>\n",
       "      <td>42.01</td>\n",
       "      <td>43.74</td>\n",
       "      <td>12020260</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-08</th>\n",
       "      <td>43.53</td>\n",
       "      <td>44.16</td>\n",
       "      <td>42.70</td>\n",
       "      <td>43.25</td>\n",
       "      <td>7139823</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             open   high    low  close    volume\n",
       "date                                            \n",
       "2022-06-27  47.20  48.05  43.88  44.09  11579012\n",
       "2022-06-28  43.57  44.00  42.88  43.44   8229144\n",
       "2022-06-29  43.13  44.47  42.90  43.58   8654650\n",
       "2022-06-30  43.61  45.68  43.61  45.00   8006156\n",
       "2022-07-01  45.02  46.23  43.95  45.36   6578720\n",
       "2022-07-04  45.48  49.00  45.31  48.59  14099456\n",
       "2022-07-05  48.65  49.00  45.09  45.86  14931320\n",
       "2022-07-06  45.77  45.82  42.00  42.87  21326163\n",
       "2022-07-07  42.87  44.44  42.01  43.74  12020260\n",
       "2022-07-08  43.53  44.16  42.70  43.25   7139823"
      ]
     },
     "execution_count": 110,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "id": "a2737168",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "open            48.65\n",
       "high            49.00\n",
       "low             45.09\n",
       "close           45.86\n",
       "volume    14931320.00\n",
       "Name: 2022-07-05 00:00:00, dtype: float64"
      ]
     },
     "execution_count": 109,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.loc[oneDay]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "id": "af4bdcf5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(open            48.65\n",
       " high            49.00\n",
       " low             45.09\n",
       " close           45.86\n",
       " volume    14931320.00\n",
       " Name: 2022-07-05 00:00:00, dtype: float64,\n",
       " open            45.48\n",
       " high            49.00\n",
       " low             45.31\n",
       " close           48.59\n",
       " volume    14099456.00\n",
       " Name: 2022-07-04 00:00:00, dtype: float64,\n",
       " open            94.13\n",
       " high            98.00\n",
       " low             90.40\n",
       " close           94.45\n",
       " volume    29030776.00\n",
       " dtype: float64)"
      ]
     },
     "execution_count": 116,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.loc[oneDay], data.loc[otherDay], data.loc[oneDay] + data.loc[otherDay]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "id": "d45fd208",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(48.65, 48.65)"
      ]
     },
     "execution_count": 117,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.loc[oneDay].open, data.loc[oneDay]['open']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "id": "50e3dd85",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "48.65"
      ]
     },
     "execution_count": 120,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.loc[oneDay]['open']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "id": "720fbede",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "48.65"
      ]
     },
     "execution_count": 121,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.loc[oneDay].open"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "id": "4b80a3a9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "48.65"
      ]
     },
     "execution_count": 122,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.loc[oneDay].open"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "id": "078655f6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "45.86"
      ]
     },
     "execution_count": 119,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.loc[oneDay].close"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "120755bd",
   "metadata": {},
   "source": [
    "#### 用坐标\n",
    "- 编程思维之 **从零开始**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "id": "54826392",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-06-27</th>\n",
       "      <td>47.20</td>\n",
       "      <td>48.05</td>\n",
       "      <td>43.88</td>\n",
       "      <td>44.09</td>\n",
       "      <td>11579012</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-06-28</th>\n",
       "      <td>43.57</td>\n",
       "      <td>44.00</td>\n",
       "      <td>42.88</td>\n",
       "      <td>43.44</td>\n",
       "      <td>8229144</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-06-29</th>\n",
       "      <td>43.13</td>\n",
       "      <td>44.47</td>\n",
       "      <td>42.90</td>\n",
       "      <td>43.58</td>\n",
       "      <td>8654650</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-06-30</th>\n",
       "      <td>43.61</td>\n",
       "      <td>45.68</td>\n",
       "      <td>43.61</td>\n",
       "      <td>45.00</td>\n",
       "      <td>8006156</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-01</th>\n",
       "      <td>45.02</td>\n",
       "      <td>46.23</td>\n",
       "      <td>43.95</td>\n",
       "      <td>45.36</td>\n",
       "      <td>6578720</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-04</th>\n",
       "      <td>45.48</td>\n",
       "      <td>49.00</td>\n",
       "      <td>45.31</td>\n",
       "      <td>48.59</td>\n",
       "      <td>14099456</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-05</th>\n",
       "      <td>48.65</td>\n",
       "      <td>49.00</td>\n",
       "      <td>45.09</td>\n",
       "      <td>45.86</td>\n",
       "      <td>14931320</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-06</th>\n",
       "      <td>45.77</td>\n",
       "      <td>45.82</td>\n",
       "      <td>42.00</td>\n",
       "      <td>42.87</td>\n",
       "      <td>21326163</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-07</th>\n",
       "      <td>42.87</td>\n",
       "      <td>44.44</td>\n",
       "      <td>42.01</td>\n",
       "      <td>43.74</td>\n",
       "      <td>12020260</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-08</th>\n",
       "      <td>43.53</td>\n",
       "      <td>44.16</td>\n",
       "      <td>42.70</td>\n",
       "      <td>43.25</td>\n",
       "      <td>7139823</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             open   high    low  close    volume\n",
       "date                                            \n",
       "2022-06-27  47.20  48.05  43.88  44.09  11579012\n",
       "2022-06-28  43.57  44.00  42.88  43.44   8229144\n",
       "2022-06-29  43.13  44.47  42.90  43.58   8654650\n",
       "2022-06-30  43.61  45.68  43.61  45.00   8006156\n",
       "2022-07-01  45.02  46.23  43.95  45.36   6578720\n",
       "2022-07-04  45.48  49.00  45.31  48.59  14099456\n",
       "2022-07-05  48.65  49.00  45.09  45.86  14931320\n",
       "2022-07-06  45.77  45.82  42.00  42.87  21326163\n",
       "2022-07-07  42.87  44.44  42.01  43.74  12020260\n",
       "2022-07-08  43.53  44.16  42.70  43.25   7139823"
      ]
     },
     "execution_count": 123,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "id": "cb134d51",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "47.2"
      ]
     },
     "execution_count": 124,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.iloc[0,0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "id": "0443e7d7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "43.61"
      ]
     },
     "execution_count": 125,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.iloc[3, 2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "id": "96d14c5c",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(47.2, 43.88, 91.08000000000001)"
      ]
     },
     "execution_count": 126,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.iloc[0,0], data.iloc[0, 2], data.iloc[0,0] + data.iloc[0, 2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "95c1192d",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "data.iloc[0,0], data.iloc[0, 3], data.iloc[0,0] + data.iloc[0, 3]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "43d2089f",
   "metadata": {},
   "source": [
    "#### 如何取一个格的数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2724093b",
   "metadata": {},
   "outputs": [],
   "source": [
    "data['close'][4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "65673429",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "data.close[4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b9348175",
   "metadata": {},
   "outputs": [],
   "source": [
    "data.open[3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "185fd6bd",
   "metadata": {},
   "outputs": [],
   "source": [
    "data.loc[data.index[3]].open"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6e22409a",
   "metadata": {},
   "outputs": [],
   "source": [
    "小括弧在Python里的含义\n",
    "1、元组\n",
    "2、方法调用\n",
    "3、表达式优先级\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f1949aaf",
   "metadata": {},
   "source": [
    "### 改变表格里的内容\n",
    "- 复制一份数据来改变"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0ae2730d",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "dataWillChange = data.copy()\n",
    "dataWillChange"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "038611e6",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "dataWillChange.iloc[0, 0] = 0\n",
    "dataWillChange"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "99c70b7e",
   "metadata": {},
   "outputs": [],
   "source": [
    "dataWillChange.open[3] = 100\n",
    "dataWillChange"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9de2a93e",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "dataWillChange['close'][2] = 300\n",
    "dataWillChange"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "465cfeaf",
   "metadata": {},
   "outputs": [],
   "source": [
    "dataWillChange.low = 0\n",
    "dataWillChange"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "03510e44",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "dataWillChange.loc[oneDay] = 1\n",
    "dataWillChange"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fd95e7cd",
   "metadata": {},
   "source": [
    "#### 我们增加一列吧"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d37c9ceb",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "dataWillChange = data.copy()\n",
    "dataWillChange"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f55885ea",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
